package cn.tworice.admin.web;

import cn.tworice.admin.service.CompaniesService;
import cn.tworice.admin.service.PostsService;
import cn.tworice.admin.service.StudentService;
import cn.tworice.common.entity.Student;
import cn.tworice.common.entity.dto.PostsDto;
import com.lmk.core.web.support.api.RequestResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin/posts")
@CrossOrigin
public class PostsController {
    @Autowired
    private PostsService postsService;

    @Autowired
    private CompaniesService companiesService;

    @GetMapping("list")
    @ApiOperation("获取职位信息列表")
    public RequestResult list(PostsDto postsDto, Integer pageSize, Integer page) {
        RequestResult result = new RequestResult();
        result.appendData("list", postsService.getList(postsDto, page, pageSize));
        result.appendData("total", postsService.getTotal(postsDto));
        return result;
    }

    @PostMapping("edit")
    @ApiOperation("编辑或添加职位信息")
    public RequestResult edit(PostsDto postsDto) {
        RequestResult result = new RequestResult();
        postsService.setPosts(postsDto);
        return result;
    }

    @DeleteMapping("del")
    @ApiOperation("删除职位信息")
    public RequestResult del(PostsDto postsDto, Integer pageSize, Integer page) {
        RequestResult result = new RequestResult();
        postsService.del(postsDto.getId());
        result.appendData("list", postsService.getList(postsDto, page, pageSize));
        result.appendData("total", postsService.getTotal(postsDto));
        return result;
    }

    @GetMapping("degree")
    @ApiOperation("获取学历列表")
    public RequestResult degree() {
        RequestResult result = new RequestResult();
        result.appendData("degree",postsService.getDegree());
        result.appendData("companies",companiesService.getList(0,50,null));
        return result;
    }
}
